package calorie.com.calorie.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.ToastUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import calorie.com.calorie.R;
import calorie.com.calorie.adapter.MyInvitationAdapter;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.contact.InviteFriendContact;
import calorie.com.calorie.response.InviteFriendResponce;
import retrofit2.Response;

/**
 * 我的邀请
 * Created by ThinkPad on 2018-11-29.
 */

public class MyInvitationActivity extends MvpActivity<InviteFriendContact.InviteFriendPresent> implements InviteFriendContact.IInviteFriendView {
    @BindView(R.id.shop_rv)
    RecyclerView shopRv;
    @BindView(R.id.rfy_shop)
    SmartRefreshLayout rfyShop;
    //好友列表数量
    @BindView(R.id.tv_FriendNum)
    TextView tv_FriendNum;
    @BindView(R.id.tv_invite_num)
    TextView tvInviteNum;
    @BindView(R.id.tv_comunity)
    TextView tvComunity;
    @BindView(R.id.tv_remove)
    TextView tv_remove;
    @BindView(R.id.et_name)
    LinearLayout etName;
    @BindView(R.id.tip_btn)
    ImageButton tipBtn;


    private List<InviteFriendResponce.DataBean.SubordinateBean> list;
    private MyInvitationAdapter myInvitationAdapter;

    @Override
    public void initData(Bundle savedInstanceState) {
        list = new ArrayList<>();
        myInvitationAdapter = new MyInvitationAdapter(R.layout.recy_item_my_invitation, list);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        shopRv.setLayoutManager(layoutManager);
        shopRv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        shopRv.setAdapter(myInvitationAdapter);
        mPresent.queryDownLineFriend(context);
        rfyShop.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresent.queryDownLineFriend(context);
            }
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_invitation;
    }

    @Override
    public void getDownDetailData(Response<InviteFriendResponce> response) {
        rfyShop.finishRefresh();
        if (response.body().getCode() == Constant.SUCCESS_CODE) {
            InviteFriendResponce.DataBean data = response.body().getData();
            if (ObjectUtils.isEmpty(data)) return;
            tvInviteNum.setText(data.getSubordinateCount() + "");
            tv_remove.setText(data.getCommunity() - data.getRemove() + "");
            tvComunity.setText(data.getCommunity() + "");
            List<InviteFriendResponce.DataBean.SubordinateBean> subordinate = data.getSubordinate();
            if (ObjectUtils.isEmpty(subordinate)) return;
            tv_FriendNum.setText("好友列表(" + subordinate.size() + ")");
            list.clear();
            list.addAll(subordinate);
            myInvitationAdapter.notifyDataSetChanged();
        } else {
            ToastUtils.showLongToast(context, response.body().getMsg());
        }
    }

    @Override
    protected InviteFriendContact.InviteFriendPresent createPresent() {
        return new InviteFriendContact.InviteFriendPresent();
    }


    @OnClick(R.id.tip_btn)
    public void onViewClicked() {
    }
}
